package com.init.engineering.service.impl;

import com.init.engineering.dao.SubitemDao;
import com.init.engineering.pages.PageResult;
import com.init.engineering.pages.QueryPageBean;
import com.init.engineering.pojo.Subitem;
import com.init.engineering.pojo.Taskplan;
import com.init.engineering.service.SubitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubitemServiceImpl implements SubitemService {

    @Autowired(required = false)
    private SubitemDao subitemDao;

    @Override
    public List<Subitem> findSubitems() {
        List<Subitem> subitems = subitemDao.findSubitems();
        return subitems;
    }

    @Override
    public PageResult findSubitemsByPage(QueryPageBean queryPageBean) {
        Integer begin = (queryPageBean.getCurrentPage() - 1) * queryPageBean.getPageSize();
        queryPageBean.setCurrentPage(begin);
        //查询当前页的数据集合
        List<Subitem> subitems = subitemDao.findSubitemByPage(queryPageBean);
        //获取分页查询的条件
        String queryString = queryPageBean.getQueryString();
        //获取分页查询按条件查询的总条数
        long totalCount = subitemDao.selectTotalCount(queryString);

        //将数据封装到PageResult内
        PageResult pageResult = new PageResult();
        pageResult.setTotal(totalCount);
        pageResult.setRows(subitems);
        return pageResult;
    }

    @Override
    public int saveSubitem(Subitem subitem) {
        int rows = subitemDao.saveSubitem(subitem);
        return rows;
    }

    @Override
    public int deleteSubitem(String suid) {
        int rows = subitemDao.updateSubitemStatus(suid);
        return rows;
    }

    @Override
    public Subitem findSubitemBySuid(String suid) {
        Subitem subitem = subitemDao.findSubitemBySuid(suid);
        return subitem;
    }

    @Override
    public int updateSubitem(Subitem subitem) {
        int rows = subitemDao.updateSubitem(subitem);
        return rows;
    }

    @Override
    public List<Subitem> findSubitemsByPid(int pid) {
        List<Subitem> subitems = subitemDao.findSubitemByPid(pid);
        return subitems;
    }
}
